home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / jockdem4.arc / NESTDEM1.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-28  |  14KB  |  306 lines

  1. Program NestTTT5_Demo_1;
  2.  
  3. uses CRT,FastTTT5,DOS,WinTTT5,KeyTTT5,StrnTTT5,NestTTT5;
  4.  
  5.  
  6. var
  7.   Hyphens,
  8.   EndProgram: Boolean;
  9.   Main_Menu,
  10.   Long_menu,
  11.   File_Menu,                       {dummy menu is a short cut to represent}
  12.   Utility_Menu,                    {all the other menus that would be used}
  13.   Dummy_Menu:Nest_Menu;            {in a large system.                    }
  14.  
  15.  
  16. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  17. {                      S E T U P    M E N U S                         }
  18. {                                                                     }
  19. {    In the first block of procedures we will set up the menus by     }
  20. {    calling the Initialize_menu proc, and the we will add menus      }
  21. {    topics to each menu by calling the Add_Topic proc.               }
  22. {                                                                     }
  23. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  24.  
  25.   Procedure SetUp_Menus;
  26.   {NOTE: The initialize_Menu proc must be called prior to trying to add
  27.          any topics to the menu. The procedure is passed four parameters:
  28.  
  29.                1) The name of the Menu - this must already been VAR declared
  30.                   with a type of Nest_Menu.
  31.  
  32.                2) The Heading for the menu.
  33.  
  34.                3) The width of the menu in characters. If a value of zero
  35.                   is used, the program will automatically compute the
  36.                   necessary width.
  37.  
  38.   }
  39.   begin
  40.       Initialize_Menu(Main_Menu,'Sprint',0,0);  {14}
  41.       Initialize_Menu(File_Menu,'File',22,12);
  42.       Initialize_Menu(Utility_Menu,'Utility',19,13);
  43.       Initialize_Menu(Long_Menu,'Potpourri',19,10);
  44.       Initialize_Menu(Dummy_Menu,'A N Other',0,0);
  45.   end; {of proc SetUp_Menus}
  46.  
  47.   {NOTE:   The add topic procedure (below) is used to add another topic
  48.            to a menu. Add the topics in the order that you want
  49.            them to appear in the menu. The Add_Topic procedure
  50.            is passed 6 parameters:
  51.  
  52.            1)  The name of the Menu to which the topic is to
  53.                be added.
  54.  
  55.            2)  The string for the topic title.
  56.  
  57.            3)  A boolean to indicate if the topic is active or
  58.                inactive. If the topic is inactive, the topic will
  59.                be displayed in an alternate color, and the cursor
  60.                bar will not land on the topic.
  61.  
  62.            4)  A character that represents a "Hot Key" that the
  63.                user can press to invoke the topic. Pass a #0 of
  64.                the topic does not have a hot key.
  65.  
  66.            5)  A unique return code (type integer) that will be
  67.                passed to the user-defined execution procedure
  68.                to indicate which topic has been chosen.
  69.  
  70.            6)  The address of a menu that will be called if the
  71.                topic is selected. If you do not want to load
  72.                another menu (i.e. its the end of the line), enter
  73.                a NIL address.
  74.  
  75.     Once a topic has been added, it can be modified with the following
  76.     procedures:
  77.                  Modify_Topic
  78.                  Modify_Topic_Name
  79.                  Modify_Topic_Active
  80.                  Modify_Topic_HotKey
  81.                  Modify_Topic_RetCode
  82.                  Modify_Topic_SubMenu
  83.   }
  84.  
  85.   Procedure Define_Main_Menu;
  86.   {}
  87.   begin
  88.       Add_Topic(Main_Menu,'File       *  Alt-F',true,#161,101,@File_Menu);
  89.       Add_Topic(Main_Menu,'Edit'              ,true,#0  ,0,@Dummy_Menu);
  90.       Add_Topic(Main_Menu,'-'                 ,true,#0  ,0  ,nil);
  91.       Add_Topic(Main_Menu,'Insert'            ,true,#0,103,@Dummy_Menu);
  92.       Add_Topic(Main_Menu,'Typestyle'         ,true,#0,104,@Dummy_Menu);
  93.       Add_Topic(Main_Menu,'Style'             ,true,#0,105,@Dummy_Menu);
  94.       Add_Topic(Main_Menu,'Layout'            ,true,#0,0,@Dummy_Menu);
  95.       Add_Topic(Main_Menu,'-'                 ,true,#0,0,nil);
  96.       Add_Topic(Main_Menu,'Print'             ,false,#0,107,@Dummy_Menu);
  97.       Add_Topic(Main_Menu,'Window'            ,true,#0,108,@Dummy_Menu);
  98.       Add_Topic(Main_Menu,'Utilities  *  Alt-U'  ,true,#150,109,@Utility_Menu);
  99.       Add_Topic(Main_Menu,'Customize'         ,true,#0,110,@Dummy_Menu);
  100.       Add_Topic(Main_Menu,'-'                 ,true,#0,0,nil);
  101.       Add_Topic(Main_Menu,'Quit'              ,true,#173,999,nil);
  102.   end; {of proc Define_Main_Menu}
  103.  
  104.   Procedure Define_File_Menu;
  105.   {}
  106.   begin
  107.       Add_Topic(File_Menu,'New'            ,true,#0,201,nil);
  108.       Add_Topic(File_Menu,'Open'           ,true,#0,202,nil);
  109.       Add_Topic(File_Menu,'Close'          ,true,#0,203,nil);
  110.       Add_Topic(File_Menu,'Insert'         ,true,#0,204,nil);
  111.       Add_Topic(File_Menu,'-'              ,true,#0,0,nil);
  112.       Add_Topic(File_Menu,'Save'           ,true,#0,205,nil);
  113.       Add_Topic(File_Menu,'Write As'       ,true,#0,206,nil);
  114.       Add_Topic(File_Menu,'Revert to Saved',true,#0,207,nil);
  115.       Add_Topic(File_Menu,'-'              ,true,#0,0,nil);
  116.       Add_Topic(File_Menu,'Translate'      ,true,#0,208,nil);
  117.       Add_Topic(File_Menu,'File Manager'   ,true,#0,209,nil);
  118.       Add_Topic(File_Menu,'Pick from List' ,true,#0,210,nil);
  119.   end; {of proc Define_File_Menu}
  120.  
  121.   Procedure Define_Long_Menu;
  122.   {}
  123.   begin
  124.       Add_Topic(Long_Menu,'bottom of File' ,true,#0,71,nil);
  125.       Add_Topic(Long_Menu,'Bottom of screen',true,#0,72,nil);
  126.       Add_Topic(Long_Menu,'case Rotate'    ,true,#0,73,nil);
  127.       Add_Topic(Long_Menu,'case Switch'     ,true,#0,74,nil);
  128.       Add_Topic(Long_Menu,'center Tab'     ,true,#0,75,nil);
  129.       Add_Topic(Long_Menu,'Decimal tab'    ,true,#0,76,nil);
  130.       Add_Topic(Long_Menu,'delete Line'    ,true,#0,77,nil);
  131.       Add_Topic(Long_Menu,'delete Word'    ,true,#0,78,nil);
  132.       Add_Topic(Long_Menu,'delete Sentence',true,#0,79,nil);
  133.       Add_Topic(Long_Menu,'delete Paragraph',true,#0,80,nil);
  134.       Add_Topic(Long_Menu,'delete End of line' ,true,#0,81,nil);
  135.       Add_Topic(Long_Menu,'reformat Document',true,#0,82,nil);
  136.       Add_Topic(Long_Menu,'eXchange cases'    ,true,#0,73,nil);
  137.       Add_Topic(Long_Menu,'lookup Zip'     ,true,#0,74,nil);
  138.       Add_Topic(Long_Menu,'Underline'      ,true,#0,75,nil);
  139.       Add_Topic(Long_Menu,'Italicize'      ,true,#0,76,nil);
  140.       Add_Topic(Long_Menu,'go Home'        ,true,#0,77,nil);
  141.       Add_Topic(Long_Menu,'Cancel undo'    ,true,#0,78,nil);
  142.   end; {of proc Define_Long_Menu}
  143.  
  144.   Procedure Define_Utility_Menu;
  145.   {}
  146.   begin
  147.       Hyphens := true;
  148.       Add_Topic(Utility_Menu,'Spelling'    ,true,#0,901,nil);
  149.       Add_Topic(Utility_Menu,'Hyphenation  *  On ' ,true,#0,902,nil);
  150.       Add_Topic(Utility_Menu,'Thesaurus'   ,true,#0,903,nil);
  151.       Add_Topic(Utility_Menu,'Glossary'    ,true,#0,904,nil);
  152.       Add_Topic(Utility_Menu,'-'           ,true,#0,0,nil);
  153.       Add_Topic(Utility_Menu,'Arrange-Sort',true,#0,905,nil);
  154.       Add_Topic(Utility_Menu,'Line Drawing',true,#0,906,nil);
  155.       Add_Topic(Utility_Menu,'-'           ,true,#0,0,nil);
  156.       Add_Topic(Utility_Menu,'Potpourri    *',true,#0,907,@Long_Menu);
  157.       Add_Topic(Utility_Menu,'QuickCard'   ,true,#0,908,nil);
  158.       Add_Topic(Utility_Menu,'Macros'      ,true,#0,909,nil);
  159.       Add_Topic(Utility_Menu,'-'           ,true,#0,0,nil);
  160.       Add_Topic(Utility_Menu,'Back Up Demo *',true,#0,910,nil);
  161.   end; {of proc Define_Utility_Menu}
  162.  
  163.   Procedure Define_Dummy_Menu;
  164.   {}
  165.   begin
  166.       Add_Topic(Dummy_Menu,'Ignite'      ,true,#0,801,nil);
  167.       Add_Topic(Dummy_Menu,'Check Boosters',true,#0,802,nil);
  168.       Add_Topic(Dummy_Menu,'Fire Retros' ,true,#0,803,nil);
  169.       Add_Topic(Dummy_Menu,'Shutdown'    ,true,#0,804,nil);
  170.       Add_Topic(Dummy_Menu,'-'           ,true,#0,0,nil);
  171.       Add_Topic(Dummy_Menu,'Launch'      ,true,#0,805,nil);
  172.       Add_Topic(Dummy_Menu,'Remove Suit',false,#0,806,nil);
  173.       Add_Topic(Dummy_Menu,'-'           ,true,#0,0,nil);
  174.       Add_Topic(Dummy_Menu,'Abort Mission',true,#0,807,nil);
  175.       Add_Topic(Dummy_Menu,'Panic'       ,true,#0,808,nil);
  176.   end; {of proc Define_Dummy_Menu}
  177.  
  178.   Procedure Paint_Screen;
  179.   {makes the screen look like a word processor}
  180.   begin
  181.       ClearText(1,1,80,25,lightgray,blue);
  182.       WriteAt(1,25,black,lightgray,
  183.       Padleft('Press F10 or / for menu.             Alt-X   to quit',80,' '));
  184.       Plainwrite(1,1,
  185.       '[     T     1         2         3         4         5         6         7     ]');
  186.       Plainwrite(5,3,'Imagine you have written a wordprocessing program and you want');
  187.       PlainWrite(5,4,'to give the program a full and powerful menu system. The NestTTT');
  188.       PlainWrite(5,5,'unit will give you all the power you need and more!');
  189.       PlainWrite(5,7,'For starters, press the F10 key or the slash key, and roam around');
  190.       Plainwrite(5,8,'the menu a little. Features include: capital letter selection, ');
  191.       Plainwrite(5,9,'optional HotKey selection, point and shoot (with full mouse support),');
  192.       Plainwrite(5,10,'non-selectable topics, line separators, auto positioning of menus and');
  193.       PlainWrite(5,11,'sub menus. The list goes on and on...');
  194.       PlainWrite(5,13,'When a menu "system" has been defined, it''s easy to call up any of the');
  195.       PlainWrite(5,14,'nested menus and bypass all the parent menus. For example, press Alt-U');
  196.       Plainwrite(5,15,'while no menu is on display - the Utility menu will automatically pop-up');
  197.       Plainwrite(5,16,'at the top level.');
  198.       PlainWrite(5,18,'All of the topics that are highlighted with an asterisk "*" are designed');
  199.       Plainwrite(5,19,'to illustrate some of the features of the menu. For example, select the');
  200.       Plainwrite(5,20,'Utility option from the main menu, or press Alt-U, and select the Potpourri');
  201.       Plainwrite(5,21,'topic. This is a menu that exceeds the no. of display lines - the menu');
  202.       Plainwrite(5,22,'will automatically scroll the topics. Also, select the Hyphenation topic');
  203.       Plainwrite(5,23,'to see a topic that can switch between two or more displays.');
  204.   end; {of proc Paint_Screen}
  205.  
  206.  
  207. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  208. {                                                                     }
  209. {         P R O G R A M    E X E C U T I O N    C O N T R O L         }
  210. {                                                                     }
  211. {    In the next block of procedures, the execution procedure or      }
  212. {    despatcher is defined. This must be declared FAR and must have   }
  213. {    the exact parameters list. This procedure is called every time   }
  214. {    a non-menu topic is selected.                                    }
  215. {                                                                     }
  216. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  217.  
  218.    Procedure Dummy_Activity(var Finish:byte);
  219.    {Saves writing a lot of real life procedures for the demo}
  220.    begin
  221.        TempMessageBox(20,5,white,red,3,'Just Imagine I did something!');
  222.        Finish := DontClear;   {return to same place in the menu}
  223.    end; {of proc Dummy_Activity}
  224.  
  225. {$F+}
  226.    Procedure Action(Var Code: integer; var Finish:byte);
  227.    {This is the main procedure the controls the execution of all
  228.     the menu options.}
  229.    begin
  230.        Case Code of
  231.        902: begin
  232.                 If Hyphens then
  233.                    Modify_Topic_name(Utility_Menu,2,'Hyphenation  *  Off')
  234.                 else
  235.                    Modify_Topic_name(Utility_Menu,2,'Hyphenation  *  On ');
  236.                 Hyphens := not Hyphens;
  237.                 Finish := RefreshTopic;
  238.             end;
  239.        910: begin
  240.                 TempMessageBox(20,5,white,red,3,'We will back up one level');
  241.                 Finish := ClearCurrent;
  242.             end;
  243.        999: begin
  244.                 sound(1000);delay(2);nosound;
  245.                 Endprogram := true;
  246.                 Finish := ClearAll;
  247.             end;
  248.        else Dummy_Activity(Finish);
  249.        end;  {case}
  250.    end; {of proc Action}
  251. {$F-}
  252.  
  253.    Procedure Menu_Loop;
  254.    {}
  255.    var Ch : char;
  256.    begin
  257.        EndProgram := false;
  258.        Repeat
  259.             Ch := Getkey;
  260.             Case Ch of
  261.             #178,                               {Alt-M}
  262.             '/',
  263.             #196 :  Show_Nest(Main_menu);       {F10}
  264.             #161 :  Show_Nest(File_Menu);       {Alt F}
  265.             #150 :  Show_Nest(Utility_menu);    {Alt U}
  266.             #027,
  267.             #173 :  Endprogram := true;         {Alt X}
  268.             end;
  269.       Until   EndProgram;
  270.    end; {of proc Menu_Loop}
  271.  
  272.  
  273. begin                                         {The main program}
  274.     ClearText(1,1,80,25,white,black);
  275.     SetUp_menus;
  276.     Define_Main_Menu;
  277.     Define_File_menu;
  278.     Define_Utility_Menu;
  279.     Define_Dummy_Menu;
  280.     Define_Long_Menu;
  281.     Nest_Despatcher :=@Action;
  282.     With NTTT do             {optionally modify default colors etc.}
  283.     begin
  284.         AllowEsc := false;
  285.         LeftSide := false;
  286.         BoxFCol := black;
  287.         BoxBCol := lightgray;
  288.         CapFCol := white;
  289.         BacCol := lightgray;
  290.         NorFCol := Black;
  291.         LoFCol := blue;
  292.         HiFCol := Lightgray;
  293.         HiBCol := blue;
  294.         LeftChar := ' ';
  295.         RightChar := ' ';
  296.     end;
  297.     Paint_Screen;
  298.     Menu_Loop;
  299.     Delete_All_Topics(Utility_Menu);
  300.     Delete_All_Topics(File_Menu);
  301.     Delete_All_Topics(Main_Menu);
  302.     Delete_All_Topics(Dummy_Menu);
  303.     Reset_StartUp_Mode;
  304. end.
  305.  
  306.